package com.ruoyi.repairs.service.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.repairs.domain.CrmRepairsRecord;
import com.ruoyi.repairs.mapper.CrmRepairsRecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.repairs.mapper.CrmRepairsMapper;
import com.ruoyi.repairs.domain.CrmRepairs;
import com.ruoyi.repairs.service.ICrmRepairsService;

/**
 * 维修Service业务层处理
 * 
 * @author hct
 * @date 2022-02-11
 */
@Service
public class CrmRepairsServiceImpl implements ICrmRepairsService 
{
    @Autowired
    private CrmRepairsMapper crmRepairsMapper;
    @Autowired
    private CrmRepairsRecordMapper crmRepairsRecordMapper;

    /**
     * 查询维修
     * 
     * @param id 维修主键
     * @return 维修
     */
    @Override
    public CrmRepairs selectCrmRepairsById(Long id)
    {
        return crmRepairsMapper.selectCrmRepairsById(id);
    }

    /**
     * 查询维修列表
     * 
     * @param crmRepairs 维修
     * @return 维修
     */
    @Override
    public List<CrmRepairs> selectCrmRepairsList(CrmRepairs crmRepairs)
    {
        return crmRepairsMapper.selectCrmRepairsList(crmRepairs);
    }

    /**
     * 新增维修
     * 
     * @param crmRepairs 维修
     * @return 结果
     */
    @Override
    public int insertCrmRepairs(CrmRepairs crmRepairs)
    {
        return crmRepairsMapper.insertCrmRepairs(crmRepairs);
    }

    /**
     * 修改维修
     * 
     * @param crmRepairs 维修
     * @return 结果
     */
    @Override
    public int updateCrmRepairs(CrmRepairs crmRepairs)
    {
        return crmRepairsMapper.updateCrmRepairs(crmRepairs);
    }

    @Override
    public int reviewCrmRepairs(CrmRepairs crmRepairs){
        CrmRepairsRecord crmRepairsRecord=new CrmRepairsRecord();
        crmRepairsRecord.setCreateTime(new Date());
        crmRepairsRecord.setRepairStatus(crmRepairs.getRepairStatus());
        crmRepairsRecord.setRepairId(crmRepairs.getId());
        crmRepairsRecord.setRemark("设置维修人");
        crmRepairsRecordMapper.insertCrmRepairsRecord(crmRepairsRecord);
        return crmRepairsMapper.updateCrmRepairs(crmRepairs);

    }

    /**
     * 批量删除维修
     * 
     * @param ids 需要删除的维修主键
     * @return 结果
     */
    @Override
    public int deleteCrmRepairsByIds(Long[] ids)
    {
        return crmRepairsMapper.deleteCrmRepairsByIds(ids);
    }

    /**
     * 删除维修信息
     * 
     * @param id 维修主键
     * @return 结果
     */
    @Override
    public int deleteCrmRepairsById(Long id)
    {
        return crmRepairsMapper.deleteCrmRepairsById(id);
    }
}
